//
//  LoginViewModel.swift
//  hunan_ios_ldnsm
//
//  Created by I-Q-I on 2019/4/28.
//  Copyright © 2019 I-Q-I. All rights reserved.
//

import Foundation
import HandyJSON


class LoginModel  {
    
    func login(by userInfo: [String: Any], completion: @escaping (_ result: Bool, _ msg: String, _ data: Any ) -> Void) {
        if userInfo["username"] as! String == "" {
            print("手机号码不能为空!")
            return completion(false, "手机号码不能为空!", "")
            
        }
        if userInfo["password"] as! String == "" {
            return completion(false, "密码不能为空!", "")
            
        }
        
        let t = TestLogin(method: .post, type: TestLoginType.login, params: userInfo)
        ApiLoadingProvider.request(t, model: User.self) { (msg, returnData) in
            if let msg = msg {
                print(msg)
            }
            
            if let returnData = returnData {
                return completion(true, "登录成功！", returnData)
            } else {
                return completion(false, "登录失败", "")
                
            }
        }
        
    }
    
}


